//
//  CYOrderCell.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/6/27.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYOrderCell.h"
@interface CYOrderCell()
@property (nonatomic, strong) CYLabel *nameLBL;//彩种名字
@property (nonatomic, strong) CYLabel *dateLBL;//彩种期号
@property (nonatomic, strong) CYLabel *bet_wayLBL;//投注方式
@property (nonatomic, strong) CYLabel *bet_moneyLBL;//投注金额
@property (nonatomic, strong) CYLabel *moneyLBL;//中奖金额
@property (nonatomic, strong) CYImageView *img;//中奖图片
@end
@implementation CYOrderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self) {
        [self setSeparatorInset:UIEdgeInsetsZero];
        [self setLayoutMargins:UIEdgeInsetsZero];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (CYLabel *)nameLBL{
    if (!_nameLBL) {
        _nameLBL = [[CYLabel alloc]initWithText:nil size:AL(16) textcolor:ColorHex(0x333333)];
        [self addSubview:_nameLBL];
        
        [_nameLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(AL(PT(24)));
            make.left.equalTo(self).with.offset(AL(PT(28)));
            make.size.mas_equalTo(_nameLBL.bounds.size);
        }];
    }
    return _nameLBL;
}

- (CYLabel *)dateLBL{
    if (!_dateLBL) {
        _dateLBL = [[CYLabel alloc]initWithText:nil size:AL(10) textcolor:ColorHex(0x888888)];
        [self addSubview:_dateLBL];
        
        [_dateLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_nameLBL.mas_right).with.offset(AL(PT(20)));
            make.centerY.equalTo(_nameLBL);
            make.size.mas_equalTo(_dateLBL.bounds.size);
        }];
    }
    return _dateLBL;
    
}

- (CYLabel *)bet_wayLBL{
    if (!_bet_wayLBL) {
        _bet_wayLBL = [[CYLabel alloc]initWithText:nil size:AL(13) textcolor:ColorHex(0x888888)];
        [self addSubview:_bet_wayLBL];
        
        [_bet_wayLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_nameLBL);
            make.top.equalTo(_nameLBL.mas_bottom).with.offset(AL(PT(24)));
            make.size.mas_equalTo(_bet_wayLBL.bounds.size);
        }];
    }
    return _bet_wayLBL;
}

- (CYLabel *)bet_moneyLBL{
    if (!_bet_moneyLBL) {
        _bet_moneyLBL = [[CYLabel alloc]initWithText:nil size:AL(13) textcolor:ColorHex(0xff5b05)];
        [self addSubview:_bet_moneyLBL];
        
        [_bet_moneyLBL mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_nameLBL);
            make.right.equalTo(self.mas_right).with.offset(- AL(PT(28)));
            make.size.mas_equalTo(_bet_moneyLBL.bounds.size);
        }];
    }
    return _bet_moneyLBL;
}

- (CYLabel *)moneyLBL{
    if (!_moneyLBL) {
        _moneyLBL = [[CYLabel alloc]initWithText:nil size:AL(13) weight:UIFontWeightBold];
        [self addSubview:_moneyLBL];
        [_moneyLBL mas_updateConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_bet_moneyLBL);
            make.centerY.equalTo(_bet_wayLBL);
            make.size.mas_equalTo(_moneyLBL.bounds.size);
        }];
    }
    return _moneyLBL;
}

- (CYImageView *)img{
    if (!_img) {
        _img = [[CYImageView alloc]initWithImageName:@"zj" size:CGSizeZero isRadius:NO];
        [self addSubview:_img];
        [_img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_moneyLBL.mas_left).with.offset(-3);
            make.centerY.equalTo(_moneyLBL);
            make.size.mas_equalTo(CGSizeMake(AL(10), AL(10)));
        }];
        
    }
    return _img;
}

- (void)setName:(NSString *)name{
    if (_name != name)
        _name = name;
    self.nameLBL.text = name;
    [self updateNameLBL];
    
}

- (void)setDate:(NSString *)date{
    if (_date != date)
        _date = date;
    self.dateLBL.text = [NSString getDateNumber:date];
    [self updateDateLBL];
    
}

- (void)setBet_way:(NSString *)bet_way{
    if (_bet_way != bet_way)
        _bet_way = bet_way;
    self.bet_wayLBL.text = bet_way;
    [self updateBet_WayLBL];
    
}

- (void)setBet_money:(NSString *)bet_money{
    if (_bet_money != bet_money)
        _bet_money = bet_money;
    self.bet_moneyLBL.text = [NSString stringWithFormat:@"投注%@元",bet_money];
    [self updateBet_MoneyLBL];
}

- (void)setMoney:(NSString *)money{
    if (_money != money)
        _money = money;
    if (_status == 1)
        self.moneyLBL.text = [NSString stringWithFormat:@"中奖%@元",money];
    else if (_status == 2)
        self.moneyLBL.text = @"待开奖";
    else if (_status == 3)
        self.moneyLBL.text = @"已撤单";
    else
        self.moneyLBL.text = @"未中奖";
    self.img.hidden = (_status == 1)?NO:YES;
    [self updateMoneyLBL];
    [self setupColor];
    
}

- (void)updateNameLBL{
    
    [_nameLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_nameLBL.bounds.size);
    }];
}

- (void)updateDateLBL{
    
    [_dateLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_dateLBL.bounds.size);
    }];
    
}

- (void)updateBet_WayLBL{
    
    [_bet_wayLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_bet_wayLBL.bounds.size);
    }];
    
}

- (void)updateMoneyLBL{
    
    [_moneyLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_moneyLBL.bounds.size);
    }];
    
}

- (void)updateBet_MoneyLBL{
    
    [_bet_moneyLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_bet_moneyLBL.bounds.size);
    }];
    
}

- (void)setupColor{
    if (_status == 1)//已中奖
        _moneyLBL.textColor = THEME_COLOR; /*开奖的红色*/
    else if (_status == 2)//待开奖
        _moneyLBL.textColor = BLUE_COLOR;//蓝色
    else if (_status == 3 || _status == 4)//已撤单||未中奖
        _moneyLBL.textColor = ColorHex(0x888888);
    _bet_moneyLBL.textColor = (_status == 3)?ColorHex(0x888888):ColorHex(0xff5b05);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
